package cool.taomu.toolkit.redisson

import com.google.auto.service.AutoService
import com.google.inject.AbstractModule
import com.google.inject.matcher.Matchers
import cool.taomu.toolkit.TaomuConfigure
import cool.taomu.toolkit.platform.inter.IPlatform
import org.redisson.api.RedissonClient
import cool.taomu.toolkit.redisson.provider.RedissonProvider

@AutoService(IPlatform)
class RedissonPlugin implements IPlatform {

    override note() {
        "Redisson 分布式锁 插件"
    }

    override module(TaomuConfigure config) {
        new AbstractModule() {
            override configure() {
                var provider = new RedissonProvider(config);
                requestInjection(provider)
                bind(RedissonClient).toProvider(provider)
                var RedissonInterceptor after = new RedissonInterceptor();
                requestInjection(after);
                bindInterceptor(
                    Matchers.any(),
                    Matchers.annotatedWith(DistributedLock),
                    after
                );
            }
        }
    }

    override start() {
    }

    override init() {
    }
    
    override packages() {
    }
}
